package org.example.thread.thread01;

import lombok.SneakyThrows;

import java.util.ArrayList;
import java.util.concurrent.FutureTask;

/**
 * @Auther:Liu
 * @Testname:Test01
 * @Date:2025/8/14 9:42
 */
public class Test01 {

    private static void a(){
        Deom01 deom01 = new Deom01();
        deom01.start();
        Deom01 deom02 = new Deom01();
        deom02.start();
    }

    public static  void b(){
        Demo02 demo02 = new Demo02();
        new Thread(demo02).start();
        Demo02 demo03 = new Demo02();
        new Thread(demo03).start();
    }

    @SneakyThrows
    public static void c(){
        Demo03 demo03 = new Demo03();
        FutureTask<String> ft = new FutureTask<>(demo03);
        new Thread(ft).start();
        FutureTask<String> ft2 = new FutureTask<>(demo03);
        new Thread(ft2).start();
        String s = ft.get();
        System.out.println(s);
    }


    public static void d1(){
        Demo04 demo04 = new Demo04();
        Demo0401 demo1 = new Demo0401(demo04);
        Demo0401 demo2 = new Demo0401(demo04);
        new Thread(demo1).start();
        new Thread(demo2).start();
    }

    public static void d2(){
        Demo0402 demo0402 = new Demo0402();
        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                demo0402.changeNUm();
            }
        };
//        Runnable runnable2 = new Runnable() {
//            @Override
//            public void run() {
//                demo0402.changeNUm();
//            }
//        };
        Runnable runnable2 = demo0402::changeNUm;
        new Thread(runnable).start();
        new Thread(runnable2).start();
    }


    public static void d3(){
        Demo0403 d3 = new Demo0403();
        Runnable r1=d3::a;
        Runnable r2=d3::a;
        new Thread(r1).start();
        new Thread(r2).start();
    }

    @SneakyThrows
    public static void d4(){
        ArrayList<String> list = new ArrayList<>();
        new Thread(() -> {
            for (int i = 0; i < 10; i++) {
                list.add(i+"");
            }
        }).start();
        new Thread(() -> {
            for (int i = 0; i < 10; i++) {
                list.add(i+"");
            }
        }).start();
        Thread.sleep(3000);
        for (String s : list) {
            System.out.println(s);
        }
    }


    public static void main(String[] args) {
        d4();
    }
}
